/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

#include "data.h"
#include "exception.h"

#include <sstream>

using namespace performance;

////////////////////////////////////////////////////////////////////////////////
//
// performance::PDT
// 
//------------------------------------------------------------------------------
// [public] construction
//

/*
PDT::PDT() {}

PDT::PDT( const PDT &rhs )
	  : type    ( rhs.type     )
	  ,	wtc     ( rhs.wtc      )
	  ,	syMSC   ( rhs.syMSC    )
	  ,	bnMSC   ( rhs.bnMSC    )
	  ,	classRef( rhs.classRef )
{}
PDT::~PDT() {}
*/

////////////////////////////////////////////////////////////////////////////////
//
// performance::PDO
// 
//------------------------------------------------------------------------------
// [public] construction
//

/*!
 *
PDO::PDO()
      : classNo( -1 )
      , lowHold( NAN )
      , midHold( NAN )
      , uppHold( NAN )
      , toSpeed( NAN )
      , toDuration( NAN )
      , toAltitude( NAN )
      , toDistance( NAN )
      , finSpeed( NAN )
      , xSection( NAN )
      , maxSpeed( NAN )
      , maxAltitude( NAN )
      , maxTurnSp( NAN )
      , is_mach( false )
      , is_jet( false )
      , stdTurnSp( NAN )
      , redTurn( NAN )
      , accTurn( NAN )
      , maxTurn( NAN )
      , redAccel( NAN )
      , accAccel( NAN )
      , maxAccel( NAN )
      , redDecel( NAN )
      , accDecel( NAN )
      , maxDecel( NAN )
      , redClimb( NAN )
      , accClimb( NAN )
      , maxClimb( NAN )
      , redDescend( NAN )
      , accDescend( NAN )
      , maxDescend( NAN )
      , levels( -1 )
	  , levelData( new std::vector< AltitudeData >() )
      , sidStar( L )
{}
 */


/*!
 *
PDO::PDO( const PDO &rhs )
      : classNo( rhs.classNo )
      , lowHold( rhs.lowHold )
      , midHold( rhs.midHold )
      , uppHold( rhs.uppHold )
      , toSpeed( rhs.toSpeed )
      , toDuration( rhs.toDuration )
      , toAltitude( rhs.toAltitude )
      , toDistance( rhs.toDistance )
      , finSpeed( rhs.finSpeed )
      , xSection( rhs.xSection )
      , maxSpeed( rhs.maxSpeed )
      , maxAltitude( rhs.maxAltitude )
      , maxTurnSp( rhs.maxTurnSp )
      , is_mach( rhs.is_mach )
      , is_jet( rhs.is_jet )
      , stdTurnSp( rhs.stdTurnSp )
      , redTurn( rhs.redTurn )
      , accTurn( rhs.accTurn )
      , maxTurn( rhs.maxTurn )
      , redAccel( rhs.redAccel )
      , accAccel( rhs.accAccel )
      , maxAccel( rhs.maxAccel )
      , redDecel( rhs.redDecel )
      , accDecel( rhs.accDecel )
      , maxDecel( rhs.maxDecel )
      , redClimb( rhs.redClimb )
      , accClimb( rhs.accClimb )
      , maxClimb( rhs.maxClimb )
      , redDescend( rhs.redDescend )
      , accDescend( rhs.accDescend )
      , maxDescend( rhs.maxDescend )
      , levels( rhs.levels )
      , altitude    ( new std::vector< double >( rhs.altitude->begin(),     rhs.altitude->end()     ) )
      , climbRate   ( new std::vector< double >( rhs.climbRate->begin(),    rhs.climbRate->end()    ) )
      , descendRate ( new std::vector< double >( rhs.descendRate->begin(),  rhs.descendRate->end()  ) )
      , acceleration( new std::vector< double >( rhs.acceleration->begin(), rhs.acceleration->end() ) )
      , deceleration( new std::vector< double >( rhs.deceleration->begin(), rhs.deceleration->end() ) )
      , cruiseSpeed ( new std::vector< double >( rhs.cruiseSpeed->begin(),  rhs.cruiseSpeed->end()  ) )
      , stallSpeed  ( new std::vector< double >( rhs.stallSpeed->begin(),   rhs.stallSpeed->end()   ) )
      , climbSpeed  ( new std::vector< double >( rhs.climbSpeed->begin(),   rhs.climbSpeed->end()   ) )
      , descendSpeed( new std::vector< double >( rhs.descendSpeed->begin(), rhs.descendSpeed->end() ) )
      , sidStar( rhs.sidStar )
{}
 */


/*!
 *
PDO::~PDO() {}
 */


////////////////////////////////////////////////////////////////////////////////
//
// performance::Data
// 
//------------------------------------------------------------------------------
// [public]
//

/*!
 *
Data::Data() : _types(), _data() {}
 */

/*!
 *
Data::~Data() {}
 */

//------------------------------------------------------------------------------
// [public] mutator interface
//

/*!
 *
void Data::add_type( const PDT& ac_type ) {
	std::string key = ac_type.type;
	if ( 0 != _types.count( key ) ) {
		key.append( 
				L == ac_type.wtc ? "L"
			  : M == ac_type.wtc ? "M"
			  :                    "H"
		);

		if ( 0 != _types.count( key ) ) {
			throw performance_data_error( 
				std::string( "Type [" ) + ac_type.type + "] already exists" 
			);
		}
	}
	_types.insert( std::make_pair( key, ac_type ) );
}
 */

/*!
 *
void Data::add_performance( const PDO& data ) {
	if ( 0 != _data.count( data.classNo ) ) {
		std::ostringstream os;
		os 
			 << "Performance Data Object [ " 
			 << data.classNo 
			 << " ] already exists";
		throw performance_data_error( os.str() );
	}
	_data.insert( std::make_pair( data.classNo, data ) );
}
 */

/*!
 *
 */
const PDT * Data::lookup_type( const std::string &id ) const {
	PDTMap::const_iterator it = _type.find( id );
	if ( _type.end() == it )
		throw performance_data_error( "illegal type id" );
	return it->second;
}

/*!
 *
 */
const PDO * Data::lookup_data( int id ) const {
	PDOMap::const_iterator it = _performance.find( id );
	if ( _performance.end() == it )
		throw performance_data_error( "illegal data id" );
	return it->second;
}


//------------------------------------------------------------------------------
